package logic

import (
	"context"
	"zhihu/mobels/mysql"

	"zhihu/zhihurpc/internal/svc"
	"zhihu/zhihurpc/zhihurpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserProblemLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserProblemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserProblemLogic {
	return &UserProblemLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserProblemLogic) UserProblem(in *zhihurpc.UserProblemRequest) (*zhihurpc.UserProblemResponse, error) {
	// todo: add your logic here and delete this line
	var problem []mysql.Problem
	mysql.DB.Debug().Where("userId = ?", in.UserId).Find(&problem)

	var userProblem []*zhihurpc.UserProblem

	for _, m := range problem {
		list := zhihurpc.UserProblem{
			Title:     m.Title,
			Content:   m.Content,
			ProblemId: int64(m.ID),
		}
		userProblem = append(userProblem, &list)
	}

	return &zhihurpc.UserProblemResponse{List: userProblem}, nil
}
